package risk.client.logic;

/**
 * @author: Pierre
 */
public class Army implements java.io.Serializable {
    private Player owner;
    private int units = 0;
    
    /**
     * Constructor, create an empty army
     * 
     * @author: Johan
     */
    public Army() {
        this.owner = null;
        this.units = 0;
    }
    
    /**
     * Construct, create an army to a player
     * 
     * @author: Johan
     */
    public Army(int units, Player player) {
        this.units = units;
        this.owner = player;
    }
    
    /**
     * Decrease units
     * 
     * @author: Johan
     * @param lessUnits
     */
    public void decreaseUnits(int lessUnits) {
        units -= lessUnits;
    }
    
    /**
     * Return the owner of an army
     * 
     * @author: Johan
     * @return player
     */
    public Player getOwner() {
        return owner;
    }
    
    /**
     * Return number of units
     * 
     * @author: Johan
     * @return units
     */
    public int getUnits() {
        return units;
    }
    
    /**
     * Increase units
     * 
     * @author: Johan
     * @param extraUnits
     */
    public void increaseUnits(int extraUnits) {
        units += extraUnits;
    }
    
    /**
     * Move army to a node
     * 
     * @author: Johan
     * @param army
     * @param amount
     */
    public void moveArmy(Army army, int amount) {
        if(amount > 0) {
            army.increaseUnits(amount);
            decreaseUnits(amount);
        } else {
            army.decreaseUnits(amount);
            increaseUnits(amount);
        }
    }
    
    /**
     * Update the owner of an army
     * 
     * @author: Johan
     * @param player
     */
    public void setOwner(Player player) {
        this.owner = player;
    }
    
    /**
     * Update the number of units
     * 
     * @author: Johan
     * @param units
     */
    public void setUnits(int units) {
        this.units = units;
    }
}